Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix type hints for _parse_requirement() #92

Merged
merged 3 commits into from
May 14, 2024

Conversation

jameslamb
Copy link
Member

Contributes to #87.

Fixes this error from mypy:

src/rapids_dependency_file_generator/_config.py:185: error: Argument "pip" to "PipRequirements" has incompatible type "str"; expected "list[str]"  [arg-type]

_parse_requirement() should never see a dictionary like {"pip": "package"}, because the dependencies.yaml requires that pip dependencies be an array.

"pip-requirements": {
"type": "object",
"properties": {
"pip": {"$ref": "#/$defs/requirements"}
},
"additionalProperties": false,
"required": ["pip"]
},

"requirements": {
"type": "array",

This fixes a type hint and a test case suggesting that possibility, and adds a new test case to ensure rapids-dependency-file-generator rejects lists like this:

dependencies:
  build:
    common:
      - output_types: [conda]
        packages:
          - beep-boop=1.2.3
          - pip
          - pip: pandas

How I tested this

Saw the new test case I added get picked up in the output of pytest -v.

Saw `rapids-dependency-file-generator raise exactly the expected error on it.

rapids-dependency-file-generator \
    --config ./tests/examples/invalid/pip-no-list/dependencies.yaml
The provided dependency file contains schema errors.

        'pandas' is not of type 'array'

        Failed validating 'type' in schema[1]['properties']['pip']:
            {'items': {'$ref': '#/$defs/requirement'},
             'minItems': 1,
             'type': 'array'}

        On instance['pip']:
            'pandas' 

...
RuntimeError: The provided dependencies data is invalid.

@jameslamb jameslamb added bug Something isn't working non-breaking Introduces a non-breaking change labels May 14, 2024
@jameslamb jameslamb changed the title fix type hints for _parse_requirement() fix: fix type hints for _parse_requirement() May 14, 2024
@jameslamb jameslamb merged commit c2ca25a into rapidsai:main May 14, 2024
4 checks passed
@jameslamb jameslamb deleted the mypy/parse-requirement branch May 14, 2024 16:19
GPUtester pushed a commit that referenced this pull request May 14, 2024
## [1.13.7](v1.13.6...v1.13.7) (2024-05-14)

### Bug Fixes

* fix type hints for _parse_requirement() ([#92](#92)) ([c2ca25a](c2ca25a))
@GPUtester
Copy link

🎉 This PR is included in version 1.13.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

difyrrwrzd added a commit to difyrrwrzd/dependency-file-generator that referenced this pull request Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working non-breaking Introduces a non-breaking change released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants